﻿using System;
using System.Web.UI.WebControls;
using MedicWeb.MedicService;

namespace MedicWeb.forms {
    public partial class InstitutionList : SessionPage {
        protected void Page_Load(object sender, EventArgs e) {
            MainService ms = new MainService();
            Institution[] institutionList = ms.GetInstitutionList(GetSession(), false);
            foreach (var institution in institutionList) {
                TableRow row = new TableRow();

                TableCell cellEdit = new TableCell();
                TableCell cellId = new TableCell();
                TableCell cellTitle = new TableCell();
                TableCell cellRegion = new TableCell();
                TableCell cellLocality = new TableCell();

                cellEdit.Controls.Add(new HyperLink() {
                    CssClass = "edit modal", 
                    NavigateUrl = ResolveUrl("~/forms/Editors/Directory/InstitutionEdit.aspx?id="+institution.Id)
                });
                cellEdit.Width = 24;
                cellId.Text = "" + institution.Id;
                cellTitle.Text = institution.Title;
                if (institution.Locality != null) {
                    cellLocality.Text = institution.Locality.Title;
                    if (institution.Locality.Region != null) {
                        cellRegion.Text = institution.Locality.Region.Title;
                    }
                }

                row.Cells.Add(cellEdit);
                row.Cells.Add(createDeleteCell(institution));
                row.Cells.Add(cellId);
                row.Cells.Add(cellTitle);
                row.Cells.Add(cellRegion);
                row.Cells.Add(cellLocality);

                tblInstitution.Rows.Add(row);
            }
        }
    }
}